//
//  MyCompanyListViewController.m
//  reSearchDemo
//
//  Created by helfy  on 15-4-16.
//  Copyright (c) 2015年 Kiwaro. All rights reserved.
//

#import "MyCompanyListViewController.h"
#import "MyCompanyViewController.h"
@interface MyCompanyListViewController ()
{
    NSMutableArray *listArray;
}
@end

@implementation MyCompanyListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isSectionMode = NO;
    self.title = @"单位公司资料";
    // Do any additional setup after loading the view.
    listArray = [NSMutableArray array];
//    [self refList];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self refList];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)setupData
{
    [super setupData];
    
    
    for (NSDictionary *address in listArray) {
        YMParameterCellObj *obj = [[YMParameterCellObj alloc] initWithObjType:YMParameterCellObjTypeLabel];
        UILabel *label = (UILabel *)obj.accessoryView;
        label.textAlignment = NSTextAlignmentLeft;
         label.font = [UIFont systemFontOfSize:16];
        label.backgroundColor = [UIColor clearColor];
        obj.arrangementType = YMParameterCellArrangementTypeVertical;
        obj.title = address[@"companyname"];
        obj.value = address[@"address"];
        obj.cellHeigth =60;
        obj.userInfo =address;
        obj.cellAction = @selector(editAddress:);
        obj.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        [self.cellObjs addObject:obj];
    }
    
 
    
    
    YMParameterCellObj *obj = [[YMParameterCellObj alloc] initWithObjType:YMParameterCellObjTypeLabel];
    
    obj.title = @"新增公司信息";
    obj.cellHeigth =45;
    obj.headImage = [UIImage imageNamed:@""];
    obj.imageSize = CGSizeMake(30, 30);
    obj.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    obj.cellAction = @selector(editAddress:);
    
    [self.cellObjs addObject:obj];
    
    [self.tableView reloadData];
}
-(void)editAddress:(YMParameterCellObj *)obj
{
    MyCompanyViewController *editCompanyViewController = [[MyCompanyViewController alloc] init];
    [editCompanyViewController setCompanyInfo:obj.userInfo];
    [self.navigationController pushViewController:editCompanyViewController animated:YMParameterCellObjTypeTextField];
}


#pragma mark - Request

- (BOOL)refList {
    
    if ([super startRequest]) {
        NSMutableDictionary * dic = [NSMutableDictionary dictionary];
        [dic setObject:[BSEngine currentEngine].user.uid forKey:@"uid"];
        [client requestFor:dic methodName:@"User/Api/getMycompany"];
    }
    
    return YES;
}

- (BOOL)requestDidFinish:(id)sender obj:(NSDictionary *)obj {
    if ([super requestDidFinish:sender obj:obj]) {
        id data = [obj getArrayForKey:@"data"];
        [listArray removeAllObjects];
        [listArray addObjectsFromArray:data];
        [self setupData];
    }
    return NO;
}
@end
